﻿using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;

using Dynamic.Data.Model.DynamicEntities.Properties;
using Dynamic.Data.Model.Collections;

namespace Dynamic.Data.Model.DynamicEntities
{
    [DataContract]
    [Serializable]
    public class DynamicEntity : DynamicEntityBase
    {
        private string _name;
        private PropertyCollection _properties;
        private DynamicEntityCollection _entities;

        public DynamicEntity()
        {
            this._properties = new PropertyCollection();
            this._entities = new DynamicEntityCollection();
        }

        public DynamicEntity(string name)
            : this()
        {
            this._name = name;
        }

        public DynamicEntity(string name, PropertyCollection properties)
        {
            this._name = name;
            this._properties = properties;
            this._entities = new DynamicEntityCollection();
        }

        public object this[string propertyName]
        {
            get
            {
                return this._properties[propertyName];
            }
            set
            {
                this._properties[propertyName] = value;
            }
        }

        [DataMember]
        [XmlAttribute]
        public string Name
        {
            get
            {
                return this._name;
            }
            set
            {
                this._name = value;
            }
        }

        [DataMember]
        [XmlArrayItem(Type = typeof(Property))]
        public PropertyCollection Properties
        {
            get
            {
                return this._properties;
            }
            set
            {
                this._properties = value;
            }
        }

        [DataMember]
        [XmlArrayItem(Type = typeof(DynamicEntity))]
        public DynamicEntityCollection Entities
        {
            get
            {
                return this._entities;
            }
            set
            {
                this._entities = value;
            }
        }
    }


}
